package com.service.luo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.luo.CluetypeDao;
import com.dao.luo.SaleClueDao;
import com.entity.Cluetype;
import com.entity.Saleclue;
import com.service.ServiceException;

@Service
@Transactional(rollbackFor=Exception.class)
public class SaleclueService {
	@Autowired
	private SaleClueDao saleclueDao;
	@Autowired
	private CluetypeDao cluetypeDao;
	
	/**
	 * 添加或更新
	 * @param saleclue
	 */
	public void saveClue(Saleclue saleclue) {
		try {
			Cluetype type = cluetypeDao.findOne(saleclue.getCluetype().getCtypeno());
			saleclue.setCluetype(type);
			saleclueDao.save(saleclue);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 查询一条线索
	 * @param clueno
	 * @return
	 */
	public Saleclue getOneClue(Long clueno) {
		return saleclueDao.findOne(clueno);
	}
	
	/**
	 * 删除一条线索
	 * @param clueno
	 */
	public void deleteOneClue(Long clueno) {
		try {
			saleclueDao.delete(clueno);
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}
	
	/**
	 * 查询所有线索类型
	 * @return
	 */
	public List<Cluetype> getAllType(){
		return (List<Cluetype>)cluetypeDao.findAll();
	}
}
